<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/4/25
 * Time: 9:57
 */

namespace app\common\model;


use think\Model;

class Operation extends Model{

    protected $insert = ['status' => 1];

    public function child(){
        return $this->hasOne(self::class, 'id', 'pid')->bind([
            'p_name' => 'name'
        ])->selfRelation();
    }

    public function setStatusAttr($value, $data){
        if ($data['status']){
            return 1;
        } else{
            return 0;
        }
    }

    public function setIsMenuAttr($value, $data){
        if ($data['is_menu']){
            return 1;
        } else{
            return 0;
        }
    }

    public function getTypeTextAttr($value, $data){
        $typeTxtArr = [1=>'系统后台', 2=>'车方后台', 3=>'商家后台'];
        return $typeTxtArr[$data['type']];
    }

    public function getCreateTimeAttr($value){
        return date('Y-m-d H:i', $value);
    }
}